//
//  DSSHTaskUpFailReasonVC.m
//  DSSH
//
//  Created by lcy on 16/4/15.
//  Copyright © 2016年 lcy. All rights reserved.
//

#import "DSSHTaskUpFailReasonVC.h"
#import "UIView+Round.h"
@interface DSSHTaskUpFailReasonVC ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UITableView*reasonTableView;
@end

@implementation DSSHTaskUpFailReasonVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupViewAndData];
    // Do any additional setup after loading the view.
}
-(void)setupViewAndData
{
    self.title = @"上画失败原因";
    self.view.backgroundColor = [UIColor whiteColor];
    UIBarButtonItem * backBarBtn = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"fanhui"] style:UIBarButtonItemStylePlain target:self action:@selector(backBarBtnClick)];
    self.navigationItem.leftBarButtonItem = backBarBtn;
    
    //添加详情表
    self.reasonTableView =[[ UITableView alloc]initWithFrame:CGRectMake(0, 0, ZYAppWidth, ZYAppHeight) style:UITableViewStylePlain];
    self.reasonTableView.delegate = self;
    self.reasonTableView.dataSource = self;
    self.reasonTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.reasonTableView];
    //添加下面的确定 整体报修按钮
    UIButton * certainBtn = [UIButton new];
    [certainBtn getRoundView:5];
    [certainBtn setTitle:@"确定" forState:UIControlStateNormal];
    certainBtn.titleLabel.font = FONT(14);
    [certainBtn setBackgroundColor:COLOR_NAVIGATE_BAR];
    [certainBtn addTarget:self action:@selector(clickCertainBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:certainBtn];
    
    UIButton * repairBtn = [UIButton new];
    [repairBtn getRoundView:5];
    [repairBtn setTitle:@"整梯报修" forState:UIControlStateNormal];
    repairBtn.titleLabel.font = FONT(14);
    [repairBtn setBackgroundColor:COLOR_NAVIGATE_BAR];
    [repairBtn addTarget:self action:@selector(clickRepairBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:repairBtn];
    
    [certainBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).with.offset(10*WIDTH_SCALE);
        make.right.equalTo(self.view.mas_right).with.offset(-10*WIDTH_SCALE);
        make.centerY.mas_equalTo(self.view.mas_centerY);
        make.height.mas_equalTo(40*HIGHT_SCALE);
    }];
    
    [repairBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).with.offset(10*WIDTH_SCALE);
        make.right.equalTo(self.view.mas_right).with.offset(-10*WIDTH_SCALE);
        make.top.equalTo(certainBtn.mas_bottom).with.offset(30*HIGHT_SCALE);
        make.height.mas_equalTo(40*HIGHT_SCALE);
    }];
}
-(void)backBarBtnClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma 点击确定按钮
-(void)clickCertainBtn
{
    
}
#pragma 点击整梯报修按钮
-(void)clickRepairBtn
{
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* cellID = @"cellID";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.textLabel.font = FONT(13);
        
        UIView *bgView = [UIView new];
        [bgView getRoundView:5];
        bgView.layer.borderWidth = 1;
        bgView.layer.borderColor = [[UIColor groupTableViewBackgroundColor]CGColor];
        [cell.contentView addSubview:bgView];
        
        [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(cell.contentView).with.offset(-5);
            make.left.equalTo(cell.contentView).with.offset(5);
            make.top.equalTo(cell.contentView).with.offset(5);
            make.bottom.equalTo(cell.contentView).with.offset(-5);
        }];
        
        UIButton * button = [UIButton new];
        button.tag = 10;
        [button setImage:[UIImage imageNamed:@"weixuan"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"dui"] forState:UIControlStateSelected];
        [button addTarget:self action:@selector(clickCellBtn:) forControlEvents:UIControlEventTouchUpInside];
        [bgView addSubview:button];
        
    }
    cell.textLabel.text = [NSString stringWithFormat:@"原因%ld",indexPath.row+1];
    UIButton * button = [cell.contentView viewWithTag:10];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(cell.contentView.mas_centerY);
        make.right.equalTo(cell.contentView).with.offset(-20*WIDTH_SCALE);
        make.size.mas_equalTo(CGSizeMake(20*WIDTH_SCALE, 20*WIDTH_SCALE));
    }];

    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60*HIGHT_SCALE;
}
-(void)clickCellBtn:(UIButton*)button
{
    UITableViewCell * cell = (UITableViewCell*)[[button superview]superview];
    cell.tag++;
    if (cell.tag%2==1)
    {
        button.selected = YES;
    }else
    {
        button.selected = NO;
       
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.tag++;
    UIButton * button = [cell.contentView viewWithTag:10];
    if (cell.tag%2==1)
    {
        button.selected = YES;
    }else
    {
        button.selected = NO;
    }

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
